package com.douleka.curd.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.douleka.curd.service.IAnnouncementService;
import com.douleka.curd.utils.Result;
import com.douleka.curd.entity.Announcement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 公告表 前端控制器
 * </p>
 *
 * @author hg
 * @since 2024-03-18
 */
@CrossOrigin
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {

    @Autowired
    IAnnouncementService announcementService;

    //查询
    @GetMapping("get")
    public Result<Object> get(Integer curr, Integer pageSize, String title, Integer type, Integer readers){
        return announcementService.get(curr,pageSize,title,type,readers);
    }

    //新增
    @PostMapping("add")
    public Result<Object> add(@RequestBody Announcement announcement){

        return announcementService.add(announcement);
    }

    //删除
    @PostMapping("delete")
    public Result<Object> delete(Integer id){
        return announcementService.delete(id);
    }


////    删除
//    @PostMapping("delete")
//    public Result<Object> completelyDelete(Integer id){
//        boolean b = announcementService.removeById(id);
//        if (!b){
//            return new Result<>("400","失败");
//        }
//        return new Result<>("200","成功");
//    }

    //修改
    @PostMapping("update")
    public Result<Object> update(@RequestBody Announcement announcement){
        return announcementService.update(announcement);
    }

}
